package com.park.web.controller.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.client.model.log.LoginLogModel;
import com.park.client.service.log.LoginLogService;
import com.park.common.constant.Constant;
import com.park.common.util.Page;
import com.park.common.util.PageData;
import com.park.common.util.Result;
import com.park.web.contant.Global;
import com.park.web.controller.BaseController;
/**
 * 日志页面
 * @author daihuajun
 *
 */
@Controller
@RequestMapping("/admin/log/login")
public class AdminLogController extends BaseController{

	@Autowired
	private LoginLogService loginLogService;
	
	@RequestMapping("listRows")
	@ResponseBody
	public PageData<LoginLogModel> listRows(Integer rows,@RequestParam(name="page",defaultValue="1")Integer pageNow,HttpServletRequest request){
		PageData<LoginLogModel>  pageData = new PageData<>();
		LoginLogModel loginLog = new LoginLogModel();
		Integer total = loginLogService.selectTotal(loginLog);
		Page page = new Page(pageNow,total,rows);
		loginLog.setStartPos(page.getStartPos());
		loginLog.setPageSize(page.getPageSize());
		List<LoginLogModel> list = loginLogService.selectPagination(loginLog);
		pageData.setTotal(total);
		pageData.setRows(list);
		return pageData;
	}
	
	/*登陆日志页面*/
	@RequestMapping("loginList")
	public String loginList(HttpServletRequest request){
			return Global.ADMIN_PATH+"log/login/loginList";
	}
	
	/**
	 * 日志删除登录用户
	 */
	@RequestMapping("deleteBatchIds")
	@ResponseBody
	public Result<Boolean> deleteByLoginId(@RequestParam("ids[]") Integer[] ids,HttpServletRequest request){
		Result<Boolean> result = new Result<>(true);
		boolean success = loginLogService.deleteBatch(ids);
		if(success){
			result.setMessage(Constant.SUCCESS_DELETE_MSG);
		}else{
			result.setSuccess(Constant.FAIL);
			result.setMessage(Constant.FAIL_DELETE_MSG);
		}
		return result;
	}
	
}
